package com.wushi.lenovo.asia5b.app_widget.bottomtab;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvp.utils.DisplayUtils;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_config.UserRepository;
import com.wushi.lenovo.asia5b.app_utils.eye.EyeUtils;

/**
 * Created by zhangyuncai on 2019/4/26.
 * 主页底部普通tabView
 */
public class WAlphaTabView extends LinearLayout {
    private ImageView iv_main_icon;
    private TextView tv_main_text;
    private TextView tv_main_count;
    private ConstraintLayout cons_main_tabvessel;

    public WAlphaTabView(Context context) {
        super(context);
        init();
    }

    public WAlphaTabView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public WAlphaTabView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WAlphaTabView);
        int type = a.getInt(R.styleable.WAlphaTabView_wTabType, 1);
        a.recycle();
        switch (type) {
            case 0:
                tv_main_text.setText(R.string.main_tab_home);
                iv_main_icon.setImageResource(R.drawable.sel_maintab_icon_home);
                ViewGroup.LayoutParams layoutParams = iv_main_icon.getLayoutParams();
                layoutParams.width = DisplayUtils.dip2px(getContext(), 25);
                iv_main_icon.setLayoutParams(layoutParams);
                break;
            case 1:
//                tv_main_text.setText(R.string.main_tab_wish);
                tv_main_text.setText(R.string.main_tab_chat);
                iv_main_icon.setImageResource(R.drawable.ic_main_chat);
                break;
            case 2:
                tv_main_text.setText(R.string.main_tab_shop);
                iv_main_icon.setImageResource(R.drawable.sel_maintab_icon_shop);
                break;
            case 3:
                tv_main_text.setText(R.string.main_tab_order);
                iv_main_icon.setImageResource(R.drawable.sel_maintab_icon_order);
                break;
            case 4:
                tv_main_text.setText(R.string.main_tab_me);
                iv_main_icon.setImageResource(R.drawable.sel_maintab_icon_me);
                break;
        }
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_alphatab, this, true);
        cons_main_tabvessel = findViewById(R.id.cons_main_tabvessel);
        iv_main_icon = findViewById(R.id.iv_main_icon);
        tv_main_text = findViewById(R.id.tv_main_text);
        tv_main_count = findViewById(R.id.tv_main_count);
    }

    @Override
    public void setSelected(boolean selected) {
        super.setSelected(selected);
        tv_main_text.setSelected(selected);
        iv_main_icon.setSelected(selected);
    }

    public void setNumber(int number) {
        EyeUtils.setNums(tv_main_count, UserRepository.isLogin() ? number : 0);
    }
}
